package com.ht.controller;

import com.alibaba.fastjson.JSON;
import com.ht.bean.*;

import com.ht.common.FileUpload;
import com.ht.service.EmpService;
import com.ht.service.KaoheService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/kaohe")
public class KaoheController {

    @Resource
    private EmpService ep;

    @Resource
    private KaoheService ks;


    //考核去查询
    @RequestMapping("/kaohetolist")
    public String kaohetolist(Model model){

        //查询部门表
        List<Dep>khlist=ks.ygkhdep();
        model.addAttribute("khlist",khlist);
        return "kaohelist";
    }

    //考核查询
    @RequestMapping("/kaohelist")
    @ResponseBody
    public Map kaohelist(Integer page,Integer limit, Aduitmodel aduitmodel,Dep dep){
        List<Map> zblist=ks.kaohelist((page-1)*limit,limit,aduitmodel,dep);
        System.out.println(zblist.toString());
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","成功");
        map.put("count",ks.kaohecount(aduitmodel,dep));//总页数
        map.put("data",zblist);//数据
        return map;
    }

    //考核指标删除
    @RequestMapping("/kaohedel")
    @ResponseBody
    public Map kaohedel(String aduitModelId){
        Map map=new HashMap();
        boolean bln=ks.kaohedel(aduitModelId);
        if (bln){
            map.put("msg","删除成功");
        }else {
            map.put("msg","删除失败");
        }
        return map;
    }



    //考核指标新增
    @RequestMapping("/kaohetoadd")
    public String kaohetoadd(Model model){
        //查询部门表
        List<Dep>yglist=ks.ygkhdep();

        //查询考核指标
        List<Aduitmodel>khzbs=ks.ygkhkhzb();
        model.addAttribute("yglist",yglist);
        model.addAttribute("khzbs",khzbs);
        return "kaoheadd";
    }

    //考核指标新增.
    @RequestMapping("/kaoheadd")
    @ResponseBody
    public Map kaoheadd(Aduitmodel aduitmodel){
        Map map=new HashMap();
        boolean bln=ks.kaoheadd(aduitmodel);
        if(bln){
            map.put("mag","添加成功");
        }else{
            map.put("mag","添加失败");
        }
        return map;
    }

    //考核指标去修改
    @RequestMapping("/kaohetoupd/{aduitModelId}")
    public String kaohetoupd(@PathVariable("aduitModelId")String aduitModelId,Model model){
        Aduitmodel aduitmodels=ks.kaohesel(aduitModelId);
        //查询部门表
        List<Dep>yglist=ks.ygkhdep();
        model.addAttribute("aduitmodels", JSON.toJSON(aduitmodels));//将对象转换成json对象
        model.addAttribute("yglist",yglist);
        return "kaoheupd";
    }

    //考核修改
    @RequestMapping("/kaoheupd")
    @ResponseBody
    public Map kaoheupd(Aduitmodel aduitmodel){
        Map map=new HashMap();
        boolean bln=ks.kaoheupd(aduitmodel);
        if(bln){
            map.put("mag","修改成功");
        }else{
            map.put("mag","修改失败");
        }
        return map;
    }


    //员工考核++++++++++++++++++++++++++++++----------------------------+++++++++++++++++++++++++++++++++++++

    //考核去查询
    @RequestMapping("/ygkhtolist")
    public String ygkhtolist(Model model){
        //查询员工表
        List<Emp>khlist=ks.ygkhemp();
        model.addAttribute("khlist",khlist);
        return "ygkhlist";
    }

    //考核查询
    @RequestMapping("/ygkhlist")
    @ResponseBody
    public Map ygkhlist(Integer page, Integer limit, Aduitlog aduitlog,Emp emp){
        List<Map> ygkhlist=ks.ygkhlist((page-1)*limit,limit,aduitlog,emp);
        System.out.println(ygkhlist.toString());
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","成功");
        map.put("count",ks.ygkhcount(aduitlog,emp));//总页数
        map.put("data",ygkhlist);//数据
        return map;
    }



    //员工考核删除
    @RequestMapping("/ygkhdel")
    @ResponseBody
    public Map ygkhdel(String aduitLogId){
        Map map=new HashMap();
        boolean bln=ks.ygkhdel(aduitLogId);
        if (bln){
            map.put("msg","删除成功");
        }else {
            map.put("msg","删除失败");
        }
        return map;
    }




    //员工管理新增
    @RequestMapping("/ygkhtoadd")
    public String weixiutoadd(Model model, HttpSession session){
        //查询部门表
        List<Dep>yglist=ks.ygkhdep();
        //查询员工表
        List<Emp>emps=ks.ygkhemp();
        //查询考核指标
        List<Aduitmodel>khzbs=ks.ygkhkhzb();
        model.addAttribute("yglist",yglist);
        model.addAttribute("emps",emps);
        model.addAttribute("khzbs",khzbs);
        return "ygkhadd";
    }

    //员工考核新增
    @RequestMapping("/ygkhadd")
    @ResponseBody
    public Map ygkhadd(Aduitlog aduitlog,HttpSession session){
        Map map=new HashMap();
        boolean bln=ks.ygkhadd(aduitlog);
        if(bln){
            map.put("mag","添加成功");
        }else{
            map.put("mag","添加失败");
        }
        return map;
    }



    //员工考核去修改
    @RequestMapping("/ygkhtoupd/{aduitLogId}")
    public String ygkhtoupd(@PathVariable("aduitLogId")String aduitLogId, Model model){
        Aduitlog aduitlog=ks.ygkhsel(aduitLogId);
        model.addAttribute("aduitlog", JSON.toJSON(aduitlog));//将对象转换成json对象
        List<Aduitmodel>aduitmodels=ks.ygkhkhzb();
        List<Emp>emps=ks.emplist();
        model.addAttribute("aduitmodels",aduitmodels);
        model.addAttribute("emps",emps);
        return "ygkhupd";
    }

    //员工考核修改
    @RequestMapping("/ygkhupd")
    @ResponseBody
    public Map ygkhupd(Aduitlog aduitlog){
        Map map=new HashMap();
        boolean bln=ks.ygkhupd(aduitlog);
        if(bln){
            map.put("mag","修改成功");
        }else{
            map.put("mag","修改失败");
        }
        return map;
    }


///////////教师考评///////////////////////////////////////////////////////////////////////////////

    //教师考评
    @RequestMapping("/jskhtolist")
    public String jskhtolist(Model model){
        List<Studentclass>sclist=ks.sclist();
        model.addAttribute("sclist",sclist);
        return "jskhlist";
    }





    @RequestMapping("/jskhlist")
    @ResponseBody
    public Map jskhtolist(Integer page, Integer limit,Jskh jskh){
        List<Map> jsklist=ks.jsklist((page-1)*limit,limit,jskh);
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","成功");
        map.put("count",ks.jskcount(jskh));//总页数
        map.put("data",jsklist);//数据
        return map;
    }

    //去发布考评
    @RequestMapping("/toaddkp")
    public String toaddkp(Model model){
        List<Kpnr> kpnrs=ks.kpnrlist();
        List<Studentclass>studentclasses=ks.sclist();
        model.addAttribute("kpnrs",kpnrs);
        model.addAttribute("studentclasses",studentclasses);
        return "jskhadd";
    }





//    发布考评
    @RequestMapping("/addkp")
    @ResponseBody
    public Map addkp(Jskh jskh){
        Map map=new HashMap();
        boolean bln=ks.jskhadd(jskh);
        if(bln){
            map.put("mag","添加成功");
        }else{
            map.put("mag","添加失败");
        }
        return map;
    }


    //*****************
//    //学生考评
//    @RequestMapping("/xstoupd/{jskhid}")
//    public String xstoupd(@PathVariable("jskhid") String jskhid, Model model){
//        Jskh ss=ks.xssel(jskhid);
//
//        model.addAttribute("ss", JSON.toJSON(ss));//将对象转换成json对象
//
//
//        return "xueshengkp";
//    }
//
//    //学生考评
//    @RequestMapping("/xsupd")
//    @ResponseBody
//    public Map xsupd(Jskh jskh){
//        Map map=new HashMap();
//        boolean bln=ks.xsupd(jskh);
//        if(bln){
//            map.put("mag","考评成功");
//        }else{
//            map.put("mag","考评失败");
//        }
//        return map;
//    }



    //教师考评删除
    @RequestMapping("/kaopdel")
    @ResponseBody
    public Map kaopdel(String jskhid){
        Map map=new HashMap();
        boolean bln=ks.jskhdel(jskhid);
        if (bln){
            map.put("msg","删除成功");
        }else {
            map.put("msg","删除失败");
        }
        return map;
    }


//    //学生考评
//    @RequestMapping("/xstolist")
//    public String xstolist(Model model){
//        List<Studentclass>sclist=ks.sclist();
//        model.addAttribute("sclist",sclist);
//        return "xueshengkplist";
//    }
//
//
//
//
////学生考评
//    @RequestMapping("/xslist")
//    @ResponseBody
//    public Map xslist(Integer page, Integer limit,Jskh jskh,HttpSession session){
//        Student stu=(Student) session.getAttribute("STU");
//        jskh.setClassid(stu.getClazz());
//        System.out.println(stu.getClazz()+"hbjhbhj");
//        List<Map> jskhlist=ks.jskhlist((page-1)*limit,limit,jskh);
//        Map map=new HashMap();
//        map.put("code",0);
//        map.put("msg","成功");
//        map.put("count",ks.jskhcount(jskh));//总页数
//        map.put("data",jskhlist);//数据
//        return map;
//    }





}
